# 测试注册功能
Write-Host "开始测试注册功能..." -ForegroundColor Green

# 测试数据
$testData = @{
    username = "testuser001"
    email = "test001@example.com"
    password = "Test123456"
    confirmPassword = "Test123456"
}

$jsonBody = $testData | ConvertTo-Json

Write-Host "发送注册请求..." -ForegroundColor Yellow
Write-Host "请求数据: $jsonBody" -ForegroundColor Cyan

try {
    $response = Invoke-RestMethod -Uri "http://localhost:5095/api/auth/register" -Method POST -ContentType "application/json" -Body $jsonBody
    
    Write-Host "注册成功!" -ForegroundColor Green
    Write-Host "响应数据:" -ForegroundColor Yellow
    $response | ConvertTo-Json -Depth 3
}
catch {
    Write-Host "注册失败!" -ForegroundColor Red
    Write-Host "错误信息: $($_.Exception.Message)" -ForegroundColor Red
    
    if ($_.Exception.Response) {
        $errorResponse = $_.Exception.Response.GetResponseStream()
        $reader = New-Object System.IO.StreamReader($errorResponse)
        $responseBody = $reader.ReadToEnd()
        Write-Host "错误响应: $responseBody" -ForegroundColor Red
    }
}

Write-Host "测试完成!" -ForegroundColor Green 